package gui;

import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.io.Console;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JComboBox;

import client.Client;

public class Questionnare extends JFrame{
	
	final public static int DEFAULT_PORT = 5555;  
    private String host = MainPanel.ip; ;  
    int j,k;
    private JLabel jLabelWelcome1 = null;
    
    
    
	
	String[] items = {"1", "2","3", "4","5", "6","7", "8","9", "10"};
	
	String[] answerString = new String[10];
	
	int value1;
	int value2;
	int value3;
	int value4;
	int value5;
	int value6;
	
	
	
	
	private JPanel mainform = null;
	private MainPanel MP;
	private JLabel jLabelWelcome = null;
	private JButton jButtonExit = null;
	private JLabel jLabelLogIn = null;
	private JButton jButton = null;
	private JButton jButton1 = null;
	private JComboBox jComboBox1 = null;

	private JComboBox jComboBox2 = null;

	private JComboBox jComboBox3 = null;

	private JComboBox jComboBox4 = null;

	private JComboBox jComboBox5 = null;

	private JComboBox jComboBox6 = null;

	
	
	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel4 = null;

	private JLabel jLabel5 = null;

	private JLabel jLabel6 = null;

	private JTextField jTextField = null;

	private JLabel jLabel7 = null;

	private JTextField jTextField1 = null;
	private JLabel jLabel8 = null;
	private JLabel jLabel9 = null;

	public Questionnare() {
		super();
		initialize();
	}

	/**
	 * 
	 */
	private void initialize() {
		this.setSize(1000, 720);
		this.setContentPane(QuestionnareForm());
		this.setTitle("Questionnare");	
				
	}
	
	/**
	 * 
	 * @return
	 */
	private JPanel QuestionnareForm() {
		if (mainform == null) {
			String[] st={"questionnare_start","tapan"};
								
			ImageIcon welcome = new ImageIcon("title-questionnaire.gif");	
			
			Client clientReport2 = new Client(host,DEFAULT_PORT);
			clientReport2.accept(st);
			Object b = clientReport2.getMsg();
			int[] wa = new int[2];
			wa=(int[])b;
			j=wa[0];
			k=wa[1]+1;
			System.out.println(wa[0]);
			System.out.println(wa[1]+1);
			
			jLabelWelcome = new JLabel();
			jLabelWelcome.setBounds(new Rectangle(77, 65, 299, 85));
			jLabelWelcome.setIcon(welcome);
			
			jLabel9 = new JLabel();
			jLabel9.setBounds(new Rectangle(230, 235, 38, 17));
			jLabel9.setText(Integer.toString(wa[1]+1));
			jLabel8 = new JLabel();
			jLabel8.setBounds(new Rectangle(176, 198, 38, 17));
			jLabel8.setText(Integer.toString(wa[0]));
			jLabel7 = new JLabel();
			jLabel7.setBounds(new Rectangle(80, 235, 147, 17));
			jLabel7.setText("questionnare number:");
			jLabel6 = new JLabel();
			jLabel6.setBounds(new Rectangle(74, 197, 98, 17));
			jLabel6.setText("survey number:");
			jLabel5 = new JLabel();
			jLabel5.setBounds(new Rectangle(621, 477, 69, 17));
			jLabel5.setText("question6");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(621, 435, 69, 17));
			jLabel4.setText("question5");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(621, 388, 69, 17));
			jLabel3.setText("question4");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(621, 338, 69, 17));
			jLabel2.setText("question3");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(621, 292, 69, 17));
			jLabel1.setText("question2");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(621, 249, 69, 17));
			jLabel.setText("question1");
			jLabelLogIn = new JLabel();
			jLabelLogIn.setBounds(new Rectangle(526, 184, 168, 35));
			jLabelLogIn.setText("questions");
			mainform = new JPanel();
			mainform.setLayout(null);
			mainform.setBackground(Color.CYAN); 
			mainform.add(getJButtonExit(), null);
			mainform.add(jLabelLogIn, null);
			mainform.add(getJButton(), null);
			mainform.add(getJButton1(), null);
			mainform.add(getJComboBox1(), null);
			mainform.add(getJComboBox2(), null);
			mainform.add(getJComboBox3(), null);
			mainform.add(getJComboBox4(), null);
			mainform.add(getJComboBox5(), null);
			mainform.add(getJComboBox6(), null);
			mainform.add(jLabel, null);
			mainform.add(jLabel1, null);
			mainform.add(jLabel2, null);
			mainform.add(jLabel3, null);
			mainform.add(jLabel4, null);
			mainform.add(jLabel5, null);
			mainform.add(jLabel6, null);
			mainform.add(jLabel7, null);
			mainform.add(jLabel8, null);
			mainform.add(jLabel9, null);	
			mainform.add(jLabelWelcome, null);
			mainform.add(jLabelWelcome, null);
			mainform.add(jLabelWelcome, null);
		}
		return mainform; 
	}

	/**
	 * This method initializes jButtonExit	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonExit() {
		if (jButtonExit == null) {
			jButtonExit = new JButton();
			jButtonExit.setBounds(new Rectangle(794, 520, 155, 64));
			jButtonExit.setText("back");
			jButtonExit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					MainEmployee MFrame = new MainEmployee();
				    MFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
				    MFrame.setSize( 1000,720 ); // set frame size
				    MFrame.setResizable(true);
				    MFrame.setVisible( true ); // display frame								    
				    Client.aFrame.dispose();   
		
				    
				    
				}
			});
		}
		return jButtonExit;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(26, 520, 158, 64));
			jButton.setText("send");
			
			/**
			 * get the data from buttons and turn them to string array 
			 */
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				
					
					value1=(jComboBox1.getSelectedIndex()+1);
					value2=(jComboBox2.getSelectedIndex()+1);
					value3=(jComboBox3.getSelectedIndex()+1);
					value4=(jComboBox4.getSelectedIndex()+1);
					value5=(jComboBox5.getSelectedIndex()+1);
					value6=(jComboBox6.getSelectedIndex()+1);  

			answerString[0]="questionnare";
			answerString[1]=Integer.toString(j);
			answerString[2]=Integer.toString(k);
			answerString[3]=Integer.toString(value1);		
			answerString[4]=Integer.toString(value2);						
			answerString[5]=Integer.toString(value3);						
			answerString[6]=Integer.toString(value4);	
			answerString[7]=Integer.toString(value5);				
			answerString[8]=Integer.toString(value6);	
			answerString[9]="1";

			
			
			Client clientReport = new Client(host,DEFAULT_PORT);
			clientReport.accept(answerString);
			j++;
			k=1;
			jLabel8.setText(Integer.toString(j));
			jLabel9.setText(Integer.toString(k));
			jComboBox1.setSelectedIndex(0);
			jComboBox2.setSelectedIndex(0);
			jComboBox3.setSelectedIndex(0);
			jComboBox4.setSelectedIndex(0);
			jComboBox5.setSelectedIndex(0);
			jComboBox6.setSelectedIndex(0);
				
				}
			});
			
			
		

				
			
			
		}
		return jButton;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(201, 520, 162, 64));
			jButton1.setText("next");
			
		
			
			/**
			 * get the data from buttons and turn them to string array 
			 */	
			jButton1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					

					value1=(jComboBox1.getSelectedIndex()+1);
					value2=(jComboBox2.getSelectedIndex()+1);
					value3=(jComboBox3.getSelectedIndex()+1);
					value4=(jComboBox4.getSelectedIndex()+1);
					value5=(jComboBox5.getSelectedIndex()+1);
					value6=(jComboBox6.getSelectedIndex()+1);

					answerString[0]="questionnare";
					answerString[1]=Integer.toString(j);
					answerString[2]=Integer.toString(k);
					answerString[3]=Integer.toString(value1);		
					answerString[4]=Integer.toString(value2);						
					answerString[5]=Integer.toString(value3);						
					answerString[6]=Integer.toString(value4);	
					answerString[7]=Integer.toString(value5);				
					answerString[8]=Integer.toString(value6);	
					answerString[9]="0";
					
			
					System.out.print(answerString[0]);
					System.out.print(answerString[1]);
					System.out.print(answerString[2]);
							
			System.out.print(answerString[3]);
			System.out.print(answerString[4]);
			System.out.print(answerString[5]);
			System.out.print(answerString[6]);
			System.out.print(answerString[7]);
			System.out.println(answerString[8]);
				
			
			
			
			Client clientReport = new Client(host,DEFAULT_PORT);
			clientReport.accept(answerString);
			k++;
			jLabel9.setText(Integer.toString(k));
			jComboBox1.setSelectedIndex(0);
			jComboBox2.setSelectedIndex(0);
			jComboBox3.setSelectedIndex(0);
			jComboBox4.setSelectedIndex(0);
			jComboBox5.setSelectedIndex(0);
			jComboBox6.setSelectedIndex(0);
			
			
			
				    
				}
			});
		}
			
			
			
		
		
		
		return jButton1;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */


	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox(items);
			jComboBox1.setBounds(new Rectangle(540, 242, 31, 26));
		}
		return jComboBox1;
	}

	/**
	 * This method initializes jComboBox2	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox2() {
		if (jComboBox2 == null) {
			jComboBox2 = new JComboBox(items);
			jComboBox2.setBounds(new Rectangle(540, 288, 31, 26));
		}
		return jComboBox2;
	}

	/**
	 * This method initializes jComboBox3	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox3() {
		if (jComboBox3 == null) {
			jComboBox3 = new JComboBox(items);
			jComboBox3.setBounds(new Rectangle(540, 333, 31, 26));
		}
		return jComboBox3;
	}

	/**
	 * This method initializes jComboBox4	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox4() {
		if (jComboBox4 == null) {
			jComboBox4 = new JComboBox(items);
			jComboBox4.setBounds(new Rectangle(540, 381, 31, 26));
		}
		return jComboBox4;
	}

	/**
	 * This method initializes jComboBox5	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox5() {
		if (jComboBox5 == null) {
			jComboBox5 = new JComboBox(items);
			jComboBox5.setBounds(new Rectangle(540, 427, 31, 26));
		}
		return jComboBox5;
	}

	/**
	 * This method initializes jComboBox6	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox6() {
		if (jComboBox6 == null) {
			jComboBox6 = new JComboBox(items);
			jComboBox6.setBounds(new Rectangle(540, 474, 31, 26));
		}
		return jComboBox6;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */


	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */

	
}  //  @jve:decl-index=0:visual-constraint="26,28"
